package medios.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import common.util.CookieManager;

public class MediosCookieUtil {

	private common.util.CookieManager ckMgr;
	private HttpServletRequest req;
	public MediosCookieUtil(HttpServletRequest req , HttpServletResponse res) {
		if(ckMgr == null) ckMgr = CookieManager.getInstance(req, res);
		this.req = req;
	}
	
	public void setAdminId(String id) {
		memberLogOut();
		ckMgr.addCookie("medAdIdCk", id);
	}
	
	public String getAdminId() {
		return ckMgr.getCookie("medAdIdCk");
	}

	public void setAdminName(String name) {
		memberLogOut();
		ckMgr.addCookie("medAdNmCk", name);
	}
	
	public String getAdminName() {
		return ckMgr.getCookie("medAdNmCk");
	}
	
	public void setMemberId(String id) {
		adminLogOut();
		ckMgr.addCookie("medMeIdCk" , id);
	}
	public String getMemberId() {
		return ckMgr.getCookie("medMeIdCk");
	}
	public void setMemberName(String name) {
		adminLogOut();
		ckMgr.addCookie("medMeNmCk" , name);
	}
	public String getMemberName() {
		return ckMgr.getCookie("medMeNmCk");
	}
	
	public void adminLogOut() {
		
		ckMgr.deleteCookie("medAdIdCk");
		ckMgr.deleteCookie("medAdNmCk");
		
	}
	
	public void setMemberSaveId(String save_id) {
		
		ckMgr.addCookie("medMeSIdCk", save_id , 3600 * 24 * 365);
	}

	public String getMemberSaveId() {
		
		return ckMgr.getCookie("medMeSIdCk");
	}
	
	public void memberLogOut() {
		
		ckMgr.deleteCookie("medMeIdCk");
		ckMgr.deleteCookie("medMeNmCk");
		
	}
	
	public boolean  isAdminLogin() {
		
		if(getAdminId().equals("")) {
			return false;
		}
		
		return true;
	}

	public boolean  isMemberLogin() {
		
		if(getMemberId().equals("")) {
			return false;
		}
		
		return true;
	}
	
	public String getIp() {
		try{
			return this.req.getRemoteHost();
		}
		catch(Exception e) {
			e.printStackTrace();
			return "";
		}
	}
	
	
}
